#ifndef __SERIALIZE_HPP__
#define __SERIALIZE_HPP__

#define BLK_SIZE 4*1024*sizeof(char)

#define INIT_CAPACITY BLK_SIZE

#define W_PTR (data_p + write_pos)
#define R_PTR (data_p + read_pos)

#define INC_W(SIZE) write_pos+=(SIZE)
#define INC_R(SIZE) read_pos+=(SIZE)

#include <string>

using namespace std;

class serialize{

public:
	char * data_p;

	unsigned int capacity;

	// write_pos is the bytes from head of buffer (data_p) for writing , 
	// in other words it's the length of data (in byte) now
	unsigned int write_pos; 

	// read_pos is the bytes from head of buffer (data_p) for reading
	unsigned int read_pos;  

public:
	serialize();
	serialize( unsigned int size );
	~serialize();

	void clean();
	int write( char * content_p , unsigned int size );
	int read( char * content_p , unsigned int size );

	serialize & operator <<( char * data_c_p 	);
	serialize & operator <<( char  data_c 		);
	serialize & operator <<( unsigned char  data_c );
	serialize & operator <<( short int  data_si 	);
	serialize & operator <<( unsigned short int  data_usi );
	serialize & operator <<( int  data_i 		);
	serialize & operator <<( unsigned int  data_i	);
	serialize & operator <<( long  data_l 		);
	serialize & operator <<( unsigned long  data_ul);
	serialize & operator <<( string  data_str 	);

	serialize & operator >>( char  & data_c 		);
	serialize & operator >>( unsigned char  & data_c );
	serialize & operator >>( short int  & data_si 	);
	serialize & operator >>( unsigned short int  & data_usi );
	serialize & operator >>( int  & data_i 		);
	serialize & operator >>( unsigned int  & data_i	);
	serialize & operator >>( long  & data_l 		);
	serialize & operator >>( unsigned long  & data_ul);
};

#endif
